package com.shujia.source

import org.apache.flink.streaming.api.scala._

object Demo01ListSource {
  def main(args: Array[String]): Unit = {
    // 创建Flink的入口
    val env: StreamExecutionEnvironment = StreamExecutionEnvironment.getExecutionEnvironment

    // 基于本地集合，例如基于List构建DataStream  --> 有界流
    val linesList: List[String] = List("java,java,spark", "spark,spark,java")

    val linesDS: DataStream[String] = env.fromCollection(linesList)

    linesDS
      .flatMap(_.split(","))
      .map(word => (word, 1))
      .keyBy(kv => kv._1)
      .sum(1)
      .print()


    // 启动任务
    env.execute()

  }

}
